package DatingSite;

import lombok.Getter;

import org.redisson.Redisson;
import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;

@Getter
public class UserStorage implements AutoCloseable {
    private String address;
    private String key;
    private RedissonClient client;
    private RQueue<User> userList;

    UserStorage() {
        this("redis://localhost:6379", "DATING_USERS_QUEUE");
    }

    UserStorage(String address, String key) {
        this.address = address;
        this.key = key;

        Config config = new Config();
        config.useSingleServer().setAddress(address);
        client = Redisson.create(config);

        userList = client.getQueue(key, new JsonJacksonCodec());
    }

    @Override
    public void close() {
        client.shutdown();
    }
}
